HTML5 & CSS3 For The Real World: Powerful HTML5 and CSS3 Techniques You Can Use Today! by Goldstein Alexis & Lazaris Louis & Weyl Estelle

HTML5 & CSS3 For The Real World: Powerful HTML5 and CSS3 Techniques You Can Use Today! by Goldstein Alexis & Lazaris Louis & Weyl Estelle

Author:Goldstein, Alexis & Lazaris, Louis & Weyl, Estelle [Goldstein, Alexis]
Language: eng
Format: azw3
ISBN: 9780987467485
Publisher: SitePoint
Published: 2015-03-09T16:00:00+00:00


The Old WebKit Syntax

Older versions of Webkit for Safari 4 and 5, Android 2.3 to 3, iOS 3.2 to 4.3, Blackberry 7, and Chrome through version 9 supported the original syntax. If you still need to support these browsers, you have to understand the syntax. But think twice before including it as the performance and memory consumption of this old syntax on old devices that require it may not make the gradient worth the effort.

Let’s look at this original syntax, using our first white-to-black gradient example again:

background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFFFFF), ↵to(#000000));

Rather than use a specific linear-gradient property, there’s a general-purpose -webkit-gradient property where you specify the type of gradient (linear in this case) as the first parameter. The linear gradient then needs both a start and end point to determine the direction of the gradient. The start and end points can be specified using percentages, numeric values, or the keywords top, bottom, left, right, or center.

The next step was to declare color stops of the gradients. You can include the originating color with the from keyword and the end color with the to keyword. Then you can include any number of intermediate colors using the color-stop function to create a color stop. The first parameter of the color-stop() function is the position of the stop expressed as a percentage, and the second parameter is the color at that location.

Here’s an example:

background-image: -webkit-gradient(linear, left top, right bottom, from(red), to(purple), color-stop(20%, orange), color-stop(40%, yellow), color-stop(60%, green), color-stop(80%, blue));

With that, we’ve recreated our angled rainbow, reminiscent of GeoCities circa 1996.

This syntax is more complicated than what was finally adopted by the W3C. Fortunately, tools exist to generate all the required code for a given gradient automatically. We’ll be looking at some of them at the end of this section, but first we’ll see how to use both syntaxes to create a cross-browser gradient for The HTML5 Herald. The good news is that since the three WebKit syntaxes use different property values, you can use them side by side without conflict. The old syntax is still supported in newer browsers, so the browser will just use whichever one was declared last. We’ve included it here mainly for legacy purposes, as you might come across this still-supported old syntax in legacy code.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.